/*
 * readH.c
 *
 *  Created on: 2011-1-7
 *      Author: zhang
 */
#include "arguments.h"
#include "crs.h"
#include <stdlib.h>
#include <stdio.h>
#include <readH.h>
/**************************************
 *
 * H is Hamiltonian matrix in CRS format
 * rowsNum is the amount of rows of H
 * elementsNum is amount of total non-zero elements in H
 *
 * **************************************/

	 void readH(CRS* H,iNum rowsNum,iNum elementsNum){

		H->elementsNum = elementsNum;
		H->rowsNum = rowsNum;
		H->colsNum = elementsNum;

		H->elements = (fNum*)malloc(sizeof(fNum) * H->elementsNum);
		H->rows = (int*)malloc(sizeof(int) * (H->rowsNum + 1));
		H->cols = (int*)malloc(sizeof(int) * H->colsNum);

		char strElements[100];
		char strCols[100];
		char strRows[100];

		sprintf(strElements,"Hamiltonian_%d_Elements",LATTICE_DIM);
		sprintf(strCols,"Hamiltonian_%d_Cols",LATTICE_DIM);
		sprintf(strRows,"Hamiltonian_%d_Rows",LATTICE_DIM);

		FILE* file = fopen(strElements,"rb");
		fread(H->elements,sizeof(fNum),H->elementsNum,file);
		fclose(file);

		file = fopen(strCols,"rb");
		fread(H->cols,sizeof(int),H->colsNum,file);
		fclose(file);

		file = fopen(strRows,"rb");
		fread(H->rows,sizeof(int),H->rowsNum + 1,file);
		fclose(file);
	}



